﻿using Microsoft.Reporting.WinForms;
using NPOI.SS.Formula.Functions;
using NPOI.XWPF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Shapes;
using WpfApp1.Report;

namespace WpfApp1
{
    /// <summary>
    /// WindowTest.xaml 的交互逻辑
    /// </summary>
    public partial class WindowTest : Window
    {
        public WindowTest()
        {
            InitializeComponent();
            getPrinters();
        }

        private string device_name;

        private void getPrinters()
        {

            List<string> list = MyPrinter.GetLocalPrinters();

            //System.Collections.ArrayList list = Printer.GetPrinterList();

            for (int i = 0; i < list.Count; i++)
            {
                string name = list[i].ToString();
                ComboBoxItem item = new ComboBoxItem();
                item.Content = name;
                combo0.Items.Add(item);
            }
        }

        private void print_btn_Click(object sender, RoutedEventArgs e)
        {

            

            string printerName = device_name;
           

            List<Orders> orders = new List<Orders>();

            Orders orders1 = new Orders("test", "1", 1, "2");

            orders.Add(orders1);



            List<ReportParameter> pr1 = new List<ReportParameter>();

            
            pr1.Add(new ReportParameter("order_number", "001", true));
            pr1.Add(new ReportParameter("time", "000", true));
            pr1.Add(new ReportParameter("description", "", true));



            string report_wenjianming = "Report5.rdlc";

            string path = Environment.CurrentDirectory;

            LocalReport localReport = new LocalReport();

            localReport.ReportPath = path + @"\Report\" + report_wenjianming;

            
            string paper_width = width_text.Text;
            string paper_height = height_text.Text;



            int width = 0;
            int.TryParse(paper_width, out width);
            if (width <= 0)
            {
                return;
            }

            int height = 0;
            int.TryParse(paper_height, out height);
            if (height <= 0)
            {
                return;
            }

            RDLCPrint aa = new RDLCPrint(false, false);
            aa.isDetail2 = false;
            aa.Run2(localReport, "DataSet1", orders, pr1, printerName, "001", "1", width, height);


        }

        private void combo0_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            if (combo0.SelectedItem == null)
            {
                return;
            }

            ComboBoxItem item0 = (ComboBoxItem)combo0.SelectedItem;
            string device_name = item0.Content.ToString();

        }
    }
}
